package com.esun.payment_api.controller;

import com.esun.common.api.CommonResult;
import com.esun.payment_api.domain.SysDictData;
import com.esun.payment_api.security.AjaxResult;
import com.esun.payment_api.service.SysDictDataService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/sysDictData")
public class SysDictDataController {

    @Resource
    SysDictDataService sysDictDataService;

    /**
     * 查询字典数据，条件查询
     */
    @GetMapping("/querySysDictDataAll")
    public CommonResult querySysDictDataAll(Short coId, String dictType, String keyword, String word) {
        try {
            List<SysDictData> list = sysDictDataService.selectByExample(coId, dictType, keyword, word);
            return CommonResult.success(list, "字典数据查询成功");
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }

    /**
     * 添加单个
     */
    @RequestMapping("/addSysDictDataOne")
    public AjaxResult addSysDictDataOne(@RequestBody SysDictData record) {
        try {
            return sysDictDataService.insertSelective(record);
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 根据id删除单个(软删除)
     */
    @RequestMapping("/deleteSysDictDataById")
    public AjaxResult deleteSysDictDataById(Short id) {
        try {
            return sysDictDataService.deleteById(id);
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 根据id修改单个
     */
    @RequestMapping("/updateSysDictData")
    public AjaxResult updateSysDictData(@RequestBody SysDictData record) {
        try {
            return sysDictDataService.updateByPrimaryKeySelective(record);
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }

}
